/**
 * Copyright 2009 Wisdom
 */
package com.wisdom.model.entities;

import javax.persistence.*;


/**
 * Entity represent of question keywords in system
 * 
 * @author alekseiko
 * @since 1.0
 */
@Entity
@Table(name="WE_KEYWORDS")
public class Keyword {

    private long id;
    private String keyword;
    private Post post;
    
    /**
     * Default keyword
     */
    public Keyword() {	
    }
    
        
    /**
     * Constructor initialize all fields
     * 
     * @param id - unique keyword id
     * @param keyword - question keyword
     * @param post - post associate with this keyword
     */
    public Keyword(long id, String keyword, Post post) {
	this.id = id;
	this.keyword = keyword;
	this.post = post;
    }



    /**
     * Get keyword id.
     * 
     * @return the id
     */
    @Id
    @Column(name = "WE_ID")
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    public long getId() {
        return id;
    }
    /**
     * Set keyword id.
     * 
     * @param id - unique keyword id in system
     */
    public void setId(long id) {
        this.id = id;
    }
    /**
     * Get question keyword.
     * 
     * @return the keyword
     */
    @Column(name="WE_KEYWORD", nullable=false, length=255)
    public String getKeyword() {
        return keyword;
    }
    /**
     * Set question keyword.
     * 
     * @param keyword - question keyword 
     */
    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }


    /**
     * Get keyword post
     * 
     * @return the post
     */
    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name="WE_POST_ID")
    public Post getPost() {
        return post;
    }


    /**
     * Set keyword post
     * 
     * @param post  - post associate with this keyword
     */
    public void setPost(Post post) {
        this.post = post;
    }


    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + (int) (id ^ (id >>> 32));
	return result;
    }


    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (obj == null)
	    return false;
	if (getClass() != obj.getClass())
	    return false;
	Keyword other = (Keyword) obj;
	if (id != other.id)
	    return false;
	return true;
    }
    
}
